﻿using CommonEntity.CommonImageEntities;
using ReactiveUI.Fody.Helpers;
using ReactiveUI;
using ScienceAppService.ModuleInterface;
using System.Reactive;
using System.Reactive.Linq;

namespace ScienceAIApp.ViewModels.SubViewModels;


/// <summary>
/// 
/// </summary>
public class LoadSeriesDescriptionViewModel : ScienceBaseViewModel
{
    private IImageShowService _imageShowService;
    private ISplitService _splitService;

    public SplitSeriesInfo? CurrentSeries { get; private set; }

    [Reactive] public string ShowDescription { get; set; }
    [Reactive] public string Dimension { get; set; }
    [Reactive] public bool IsChecked { get; set; }
    

    public ReactiveCommand<Unit, Unit> ChooseSeriesCommand;

    public Interaction<string, Unit> ChooseSeriesInteraction;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="imageShowService"></param>
    public LoadSeriesDescriptionViewModel(IImageShowService imageShowService, ISplitService splitService)
    {
        _imageShowService = imageShowService;
        _splitService = splitService;

        ShowDescription = "";
        Dimension = "";
        ChooseSeriesInteraction = new Interaction<string, Unit>();

        ChooseSeriesCommand = ReactiveCommand.CreateFromTask(async () =>
        {
            if (CurrentSeries == null) return;
            await ChooseSeriesInteraction!.Handle(CurrentSeries.Key);
        });
        
    }

    /// <summary>
    /// 设置序列
    /// </summary>
    /// <param name="si"></param>
    public void SetSeries(SplitSeriesInfo? si)
    {
        if (si == null)
        {
            CurrentSeries = null;
            ShowDescription = "";
            Dimension = "";
        }
        else
        {
            CurrentSeries = si;
            ShowDescription = si.SeriesDescription;
            Dimension = si.Dimension;
        }
    }

}
